﻿using System;
using System.Threading.Tasks;

namespace Loong.Runtime.Caching
{
    public interface ICache
    {
        object GetOrCreate(string key, Func<CacheOptions, object> factory);
        TValue GetOrCreate<TValue, TKey>(TKey key, Func<CacheOptions, TValue> factory);
        Task<object> GetOrCreateAsync(string key, Func<CacheOptions, Task<object>> factory);
        Task<TValue> GetOrCreateAsync<TValue, TKey>(TKey key, Func<CacheOptions, Task<TValue>> factory);
        object Get(string key);
        TValue Get<TValue, TKey>(TKey key);
        Task<object> GetAsync(string key);
        Task<TValue> GetAsync<TValue, TKey>(TKey key);
        void Set(string key, object value, TimeSpan expireTime);
        void Set<TValue, TKey>(TKey key, TValue value, TimeSpan expireTime);
        Task SetAsync(string key, object value, TimeSpan expireTime);
        Task SetAsync<TValue, TKey>(TKey key, TValue value, TimeSpan expireTime);
        void Remove(string key);
        void Remove<TKey>(TKey key);
        Task RemoveAsync(string key);
        Task RemoveAsync<TKey>(TKey key);
        void Clear();
        Task ClearAsync();
    }
}
